<?php require_once('Connections/CSRE_Connection.php'); ?>

<?php

mysql_select_db($database_CSRE_Connection, $CSRE_Connection);
$query_banner = "SELECT `path` FROM csre_banner WHERE selected = 1";
$banner = mysql_query($query_banner, $CSRE_Connection) or die(mysql_error());
$row_banner = mysql_fetch_assoc($banner);
$totalRows_banner = mysql_num_rows($banner);

$error = "";
$success = "";

if (isset($_POST['retrievepass'])) {
	
	$mail=$_POST['mail'];
	
	mysql_select_db($database_CSRE_Connection, $CSRE_Connection);
	  
	$loginQuery = sprintf("SELECT `pass` FROM csre_client WHERE pri_email = '%s'", $mail);
	  
	$result = mysql_query($loginQuery, $CSRE_Connection) or die(mysql_error());
	$row_clave = mysql_fetch_assoc($result);
	$loginFoundUser = mysql_num_rows($result);

	if ($loginFoundUser) {
		
		$pass = $row_clave['pass'];
		
		$cabeceras = "From: test@test.com\r\nContent-type: text/html\r\n";
		$asunto = "Locamedic CSRE retrouver mot de passe";
		$mensaje = "Vous avez demande votre mot de passe.";
		$mensaje = $mensaje . "<br>";
		$mensaje = $mensaje . "Votre mot de passe: ";
		$mensaje = $mensaje . $pass;

		mail($mail, $asunto, $mensaje, $cabeceras);
		
		$success = "Votre mot de passe a ete envoye";
		
	} else {
		$error = "Courriel pas trouve";
	}


	$row_user = mysql_fetch_assoc($result);
	
}

?>



<?php include('CSRE_header.php');?>
	
	<div align="center">
		<span style="background-color:#FFFFFF;">
			<table class="base_table">
				<tr>
				<td valign="top" width="200">
					<?php include('CSRE_left_menu.php'); ?>
				</td>
				
				<td style="background-image:url('images/divider.gif'); background-repeat:repeat-y;"></td>
				
				<td valign="top">
									
					<table width="100%">
						<tr valign="top">
							<td class="title_csre" style="background-color:#6AAA67;">
								R&eacute;cup&eacute;rer mot de passe
							</td>
						</tr>
						<?php if (strlen($error) > 0) { ?>
						<tr>
							<td></td>
						</tr>
						<tr>
							<td>
								<table>
									<tr>
										<td width="30">
											<img src="img/icons/fail.gif" />
										</td>
										<td class="text_error">
											<?php echo $error; ?>
										</td>
									</tr>
								</table>
							</td>
						</tr>
						<?php } ?>
						<?php if (strlen($success) > 0) { ?>
						<tr>
							<td></td>
						</tr>
						<tr>
							<td>
								<table>
									<tr>
										<td width="30">
											<img src="img/icons/success.gif" />
										</td>
										<td class="text_error" style="color: green;">
											<?php echo $success; ?>
										</td>
									</tr>
								</table>
							</td>
						</tr>
						<?php } ?>
						<tr>
							<td height="5"></td>
						</tr>
						<tr>
							<td>
								<?php if (1==0) { ?>
									<img src="images/csre/banner/<?php echo $row_banner['path']; ?>">
								<?php } ?>
							</td>
						</tr>
						<tr>
							<td align="left">
								<form ACTION="CSRE_forgot_pass.php" name="loginForm" method="POST">
								<table cellpadding="10" width="70%">
									<tr>
										<td class="text">
											Courriel
										</td>
										<td>
											<input type="text" name="mail" />
										</td>
									</tr>
									<tr>
										<td>&nbsp;</td>
										<td>
											<button  type="submit" name="getPass" style="margin:0;padding:0;border:0; background-color:#FFFFFF; cursor:pointer;">
<table cellpadding="0" cellspacing="0" style="background-image:url(button_bg.gif); background-repeat:repeat-x;">
<tr><td><img src="button_left.gif" /></td><td><span style="font-family:Verdana, Helvetica, sans-serif; font-weight:bold; color:#FFFFFF; font-size:10px;">Rechercher Mot de Passe</span></td><td><img src="button_right.gif"></td></tr>
</table></button>
										</td>
									</tr>
								</table>
								<input type="hidden" name="retrievepass" value="retrievepass" />
							  </form>
							</td>
						</tr>
					
					</table>
				</td>
				</tr>
			</table>
		</span>
	</div>

<?php include('CSRE_footer.php'); ?>
<?php
mysql_free_result($banner);

mysql_free_result($clave);
?>
